package com.ktjy.service.impl;

import com.ktjy.entity.Auctionuser;
import com.ktjy.mapper.AuctionUserMapper;
import com.ktjy.service.AuctionUserService;
import com.ktjy.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

/**
 * @Author: DABINGCHNEGJIAO
 * @CreateTime: 2025-06-14
 * @Description:
 * @Version: 1.0
 */
public class AuctionUserServiceImpl implements AuctionUserService {

    @Override
    public boolean registerAuctionuser(Auctionuser auctionuser) {
        try (SqlSession sqlSession = MyBatisUtil.createSqlSession()) {
            try {
                AuctionUserMapper mapper = sqlSession.getMapper(AuctionUserMapper.class);
                boolean result = mapper.registerAuctionuser(auctionuser) > 0;
                sqlSession.commit(); // 提交事务
                return result;
            } catch (Exception e) {
                sqlSession.rollback(); // 回滚事务
                throw e;
            }
        }
    }

    @Override
    public Auctionuser loginAuctionuser(String username, String password) {
        try (SqlSession sqlSession = MyBatisUtil.createSqlSession()) {
            AuctionUserMapper mapper = sqlSession.getMapper(AuctionUserMapper.class);
            return mapper.loginAuctionuser(username, password);
            // 查询操作通常不需要显式提交/回滚
        }
    }

}
